/*
 * @Author: your name
 * @Date: 2020-05-13 22:43:27
 * @LastEditTime: 2020-05-14 21:12:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \ts\ts_test\class.ts
 */
class Animal {
  public name:string;
  //只能在类里面访问，子类也无法访问
  private _privatestring:string = '类里面访问，子类也无法访问';
  //只能在类里面访问，子类可以访问
  protected myprotected:string = '类里面访问，子类可以访问';

  static isAnimal(a : any):boolean {
    return a instanceof Animal
  }
  //静态属性
  static categoies:string[] = ["静态"];
  constructor(name:string){
    this.name = name
  }
  run():string{
    return `${this.name} is running`
  }
  show(){
    console.log("我是父类的方法")
    console.log(this._privatestring)
    console.log(Animal.categoies)
  }
}

const snake = new Animal("动物")
console.log(snake.run())
console.log(Animal.isAnimal(snake))
// snake._privatestring 属性“_privatestring”为私有属性，只能在类“Animal”中访问

class Dog extends Animal {
  age:number;
  constructor(name:string,age:number){
    super(name)
    this.age = age
  }
  bark(){
    //this._privatestring //属性“_privatestring”为私有属性，只能在类“Animal”中访问
    console.log(this.myprotected)
    return `${this.name} ${this.age} is barking`
  }
}
const xiaogou = new Dog("小狗",2);
console.log(xiaogou.run())
console.log(xiaogou.bark())
console.log(Animal.isAnimal(xiaogou))

class Cat extends Animal {
  constructor(name:string){
    super(name)
    console.log(this.name)
  }

  run() : string{
    super.show()
    return `Meow ${this.name} is running`
  }
}
const xiaomao = new Cat('小猫')
console.log(xiaomao.run())
